// pages/recharge-money/index.js
var wxcashpay = require('../../utils/pay.js')
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selectId:"",
    cashItemArr:[],
    moneyAmount:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.cashItemList()
  },
  //添加充值订单
  formSubmitOrder:function(e){
    var that = this
    var money = e.detail.value.money
    if(money == ""){
      wx.showModal({
        title: '提示',
        content: '请输入金额',
        showCancel: false
      })
      return;
    }
    wx.request({
      url: app.globalData.host + '/api/UserCash/SubmitOrder?uid=' + app.globalData.userInfo.Uid + '&storeId=' + app.globalData.storeId + '&amount=' + money,
      success: function(res) {
        if(res.data.Code == 0){
          var oid = res.data.Data
          //支付
          wxcashpay.wxcashpay(app, oid, "/pages/recharge/index");
          return;
        }
      },
    })
  },
  //获取充值选项
  cashItemList:function(){
    var that = this
    wx.request({
      url: app.globalData.host + '/api/UserCash/CashItemList?storeId=' + app.globalData.storeId,
      success: function(res) {
        if(res.data.Code == 0){
          that.setData({
            cashItemArr:res.data.Data.List
          })
        }
      },
    })
  },
  //选择充值活动
  chooseMoney:function(e){
    var selectId = e.currentTarget.dataset.selectid
    var amount = e.currentTarget.dataset.amount
    this.setData({
      selectId: selectId,
      moneyAmount: amount
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})